<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>PetStore Management</title>
<!--    <link rel="Stylesheet" href="../css/jpetstore.css" type="text/css" media="screen"/>-->
    <script th:src="@{../js/jquery-3.6.0.min.js}"></script>
</head>
<style>
    *{
        padding: 0px;
        margin: 0px;
    }
    #Content {
        width: 100%;
        height: 60ex;
        color: #333;
        background-color: rgba(256,256,256,0.5);
        border-width: 0;
        position: relative;
        overflow: hidden;

    }
    a{
        display: block;
        text-decoration: none;
        color: #eaac00;
        font-weight: bold;
    }
    .Returnto{
        display: inline-block;
        float: left;
        position: absolute;
        top: 1ex;
        left: 2ex;
        height: 5ex;
        width: 50ex;
        background-image: url("../image/ReturntoManagementMainMenu.png");
        background-size: 100%;
        background-repeat: no-repeat;
        border-color: #eaac00;
        border-width: 0.4ex;
        border-style: solid;
    }
    table{
        display: block;
        /*position: absolute;*/
        /*top: 10ex;*/
        /*left: 10ex;*/
        margin-top: 10%;
        margin-left: 32%;
        width: 45ex;
        font-size: 3ex;
        background-color: #ffffff;
        border-color: #56832c;
        border-width: 1ex;
        border-style: solid;
        margin-bottom: 10ex;
    }
    table tr{
        height: 3ex;
        text-align: left;
    }
    table td{
        width: 10ex;
    }
    h2{

        float: left;
        position: absolute;
        top: 1ex;
        left: 8ex;
        font-size: 5ex;
    }
    input {
        float: left;
        position: absolute;
        border-width: .3ex .3ex .3ex .3ex;
        border-style: solid;
        border-color: #eaac00;
        background-color: #ffffff;
        color: #eaac00;
        height: 3ex;
        font-size: 3ex;
    }
    label{
        display: inline-block;
        float: left;
        position: absolute;
        font-size: 3ex;
    }
    #Catalog{
        width: 80ex;
        height: 45ex;
        background-color: #ffffff;
        margin-top: 5ex;
        margin-bottom: 1ex;
        margin-left: 30%;
        position: relative;
        border-color: #56832c;
        border-width: 1ex;
        border-style: solid;
    }
    .return{
        position: absolute;
        display:inline-block;
        background-image: url("../image/RETURN.png");
        background-size: 100%;
        background-repeat: no-repeat;
        width: 10ex;
        top: 31ex;
        left: 15ex;
        height:3ex;
    }
</style>
<body>
<div th:replace="manageCommon/managetop"></div>
<div id="Content">
    <a class="Returnto" href="/manage/main"></a>
    <div id="Catalog">
        <h2>Category Register</h2>
<!--        /manage/addCategory-->
        <form action="/manage/addCategory" method="post" id="addCategory" enctype ="multipart/form-data">
            <label style="left: 7ex;top: 7ex ">Category ID: </label>
            <input style="left: 19ex;top: 6ex ;width: 15ex"  type="text" id="categoryid" name="categoryid" /><br/>
            <label style="left: 3.8ex;top: 12ex ">Category Name: </label>
            <input style="left: 19ex;top: 12ex ;width: 15ex" type="text" id="name" name="name" /><br/>
            <label style="left: 3.5ex;top: 18ex ">Category Image:</label>
            <input style="left: 19ex;top: 18ex;width: 20ex" type="file" id="imagepath" name="imagepath"><br/>
<!--            th:onclick="isPot()"-->
            <input style="left: 20ex;top: 25ex;width: 10ex " type="submit" value="Submit" id="save"/>
        </form>
        <input class="return" type="button"  th:onclick="backCategoryList()"/>
    </div>
    <script>
        function backCategoryList(){
            location.href = "/manage/intoPetManage";
        }
        window.onload=function(){
            var mysubmit=document.getElementById('save');
            mysubmit.onclick=function(event){
                var category = document.getElementById("categoryid").value;
                if(category.length===0||category===null){
                    window.alert("categoryId不可为空");
                    event.preventDefault();
                }else{
                    let datas={"key":"123"};
                    console.log("1111111111");
                    $.post('/manage/newCategoryIdIsExist?newcategoryid='+category,datas,function (data) {
                        console.log("222222");
                        if(data.code===0){
                            window.alert("categoryId已存在");
                            console.log("33333333");
                            document.getElementById("categoryid").value="";
                            event.preventDefault();
                        }else if(data.code===1){
                            console.log("44444444444");
                            var name = document.getElementById("name").value;
                            if(name.length===0||name===null){
                                window.alert("categoryName不可为空");
                                console.log("555555555");
                                event.preventDefault();
                            }else{
                                console.log("66666666");
                            }
                        }else{
                            event.preventDefault();
                        }
                    });
                }
            }
        }
    </script>
</div>
<div th:replace="manageCommon/managebottom"></div>
</body>
</html>